const { app, BrowserWindow} = require('electron')
const path = require('path')
const WinState = require('electron-win-state').default

require('./controller/alert')
require('./controller/openFile')
require('./controller/getDatabases')
require('./controller/getPaper')
require('./controller/saveExamDate')
require('./controller/makeFile')
require('./controller/deleteExamData')
require('./controller/saveFile')
require('./controller/saveJsonFile')
require('./controller/updateJsonFile')

const createWindow = () => {
    const winState = new WinState({
        dafaultWidth: 12000,
        defaultHeight: 800,
        electronStoreOptions: {
            name: 'window-state-main'
        }
    })
    const win = new BrowserWindow({
        ...winState.winOptions,
        title: "特酷",
        minWidth: 1200,
        minHeight: 700,
        webPreferences: {
            // nodeIntegration: true,
            //  contextIsolation: false,
            webSecurity: false,
            preload: path.resolve(__dirname,"./preload")
        },
        autoHideMenuBar: true,

    })
    win.loadURL("http://localhost:5173")
    // win.loadFile('./test/index.html')
    winState.manage(win)
}

app.whenReady().then(() => {
    createWindow()

    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) {
            createWindow()
        }
    })
})

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit()
    }
})